{% extends "layouts/baseview.html" %}
{% load i18n %}

{% load short_uri %}
{% block stylesheet %}
	<link rel="stylesheet" href="/css/user-min.css" />
{% endblock %}
{%block title%}messages{%endblock%}

{% block extrastyle %}
<script type="text/javascript">
function del_msg(elm, msgid) {
    q_get('msg/del', {'m':msgid}, function() {
	show_info('{%trans "del message ok!"%}');
	elm.remove();
    }, function() {
	show_info('{%trans "can not del message!"%}');	
    });    
}

function move_msg(elm, msgid, target) {    
    q_get('msg/move', {'m':msgid, 't':target}, function() {
	show_info('{%trans "move message ok!"%}');
	elm.remove();
    }, function() {
	show_info('{%trans "can not move message!"%}');	
    });
}
</script>
<script type="text/javascript" src="/js/sendmsg-min.js"></script>
{% endblock %}

{%block ready_js%}

   $('tr[name^="msg-"]').each(function() {
       var msg = $(this);
       var msg_id = msg.find('#msg-id').val();
       
       msg.find('#del').confirm('{%trans "Are you sure delete this message?"%}', '{%trans "Yes"%}', '{%trans "No"%}', function() {
	   if ('{{boxname}}' != 'trashbox') {
	       move_msg(msg, msg_id, 'trashbox');
	   } else {
	       del_msg(msg, msg_id);
	   }
       });
       
       msg.find('#btn-send').click(function(e) {
	   show_send_box(e.pageX, e.pageY, msg.find('#msg-sender').val());
       });
       
       msg.find('#recovery').click(function() {
	   if (msg.find('#msg-sender').val() == '1'){ // sender is me , recovery into outbox
	       move_msg(msg, msg_id, 'outbox');
	   } else {
	       move_msg(msg, msg_id, 'inbox');
	   }	
       });
   });

{%endblock%}
	{% block main-nav %} 

	
	{% endblock %}
	
{%block main-block%}
<div class="d-g-wrapper d-p-user">

	<div class="d-p-user-top">
		<h2 class="d-p-project-name"><a href="/project/explore">{% trans "main" %}</a><span>&nbsp;&nbsp;>&nbsp;&nbsp;</span><a href="{{user|url}}">{{user.name}}</a>
		</h2>
		
		


{%if navmenusMsg%}
<ul class="layout d-p-user-tabs">
	  {%for m in navmenusMsg%}
	  {%if m.choice%}
	  <li class="d-p-user-tab">
	    <a href="{{m.uri}}/" class="current">{{m.txt}}</a>
	  </li>
	  {%else%}
	  <li class="d-p-user-tab">
	    <a href="{{m.uri}}/">{{m.txt}}</a>
	  </li>
	  {%endif%}
	  {%endfor%}
</ul>
{%endif%}
		
	<div class="d-p-user-content">
          <table class="d-p-user-message">
              <tbody>
                  <tr>
                  	  {%if boxname == 'inbox'%}
                      	<th width="150" class="d-p-message-colfirst">{%trans "sender"%}</th>
                      {%else%}
                      	<th width="150" class="d-p-message-colfirst">{%trans "receiver"%}</th>
                      {%endif%}
                      <th>{%trans "message content"%}</th>
                      <th width="222">{%trans "send time"%}</th>
                  </tr>
                  {%for msg in page.object_list%}
                   <tr name= "msg-{{msg.id}}" valign= "top">
                      <td class="d-p-message-colfirst">{%if msg.sender == user%}
					       <a href= "{{msg.owner|url}}" class="d-g-orange">
					        {{msg.owner}}
					       </a>
					      {%else%}
					       <a href= "/u/{{msg.sender.name}}/" class="d-g-orange">
					        {{msg.sender}}
					       </a>   
					      {%endif%}
					</td>
					<td class="d-p-message-colsecond">

						  <input id= "msg-id" type= "hidden" value= "{{msg.id}}" />
						{%if msg.sender == user and boxname == 'outbox'%}
				        	<!-- To <a href= "{{msg.owner|url}}" class="d-g-orange">{{msg.owner}} </a> -->
				        {%else%}
				        	<!-- From <a href= "{{msg.sender|url}}" class="d-g-orange">{{msg.sender.name}} </a> -->
				        <input id= "msg-sender" type= "hidden" value= "{{msg.sender.name}}"/>
				        {%endif%}
				         {{msg.content|linebreaks|urlize}} 
				         
				         
				         {%if boxname == 'trashbox'%}
        					<a class= "" href= "javascript:;" id= "recovery" >{%trans "recovery"%}</a>
        				{%endif%}
        				<p>
        				{%if msg.owner == user%}
					        <input id= "im-sender" type= "hidden" value= "1" />
					        <a class= "" href= "javascript:;" id= "btn-send" >{%trans "reply"%}</a>
					    {%endif%}
				          <a class= "" id= "del" href= "javascript:;" >{%trans "delete"%}</a>
				          
				         </p>
		
					</td>
					<td>{{msg.send_time|difftime}}</td>
            
                  </tr>
                  {%endfor%}
                  
              </tbody>
          </table>
          {% include "layouts/page-nav.html" %}
      </div>
	
	
		
		

{%endblock%}

